﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DQYT.HTDZ.BLL;
using System.Data;
using DQYT.HTDZ.Model;
using DQYT.HTDZ.DBUtility;
using DQYT.HTDZ.Common;
using System.Reflection;
using DQYT.HTDZ.BusinessService;
using System.Threading;
using System.Xml;
using System.IO;
using System.Text;

namespace DQYT.HTDZ.Web.Views.SGTZD
{
    /// <summary>
    /// 获取井号和采集日期数据
    /// </summary>
    public partial class SGTZDMAIN_Handler : System.Web.UI.Page
    {
        private string cjrq_s;//采集日期范围的最小值
        private string cjrq_e;//采集日期范围的最大值
        private string selectWellid;//单井的井号
        private DataTable drawTb;//保存时间段中查询出的数据
        private DataTable currentTb = new DataTable();//临时数据表
        private BDDATESOURSEBLL dataSourseBll = new BDDATESOURSEBLL();
        private DrawFunc drawFunc = new DrawFunc();//描图类
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {

                int pageSize = 0, pageIndex = 0, recordCount=0;

                string format = "\"total\":{0}, \"rows\":{1}";  
                int.TryParse(Request.Form["rows"], out pageSize);
                int.TryParse(Request.Form["page"], out pageIndex);

                if (pageSize == 0) pageSize = 10;
                if (pageIndex == 0) pageIndex = 1;


                 selectWellid = Request.QueryString["id"];
                 cjrq_s = Request.QueryString["TimeS"];
                 cjrq_e = Request.QueryString["TimeE"];

                if (selectWellid == null && cjrq_s == null)
                    this.drawTb = drawFunc.getcurdata(pageSize,pageIndex,out recordCount);
                else if (selectWellid != null)
                    this.drawTb = drawFunc.getWellList_DateAndID(this.cjrq_s, this.cjrq_e, this.selectWellid, pageSize, pageIndex, out recordCount);
                else
                    this.drawTb = drawFunc.getWellList_Date(this.cjrq_s, this.cjrq_e, pageSize, pageIndex, out recordCount);

                string strJson = JsonHelper.ToJson(this.drawTb);
                strJson = "{" + string.Format(format, recordCount,
                       string.IsNullOrWhiteSpace(strJson) ? "[]" : strJson) + "}";

                Response.ContentType = "text/json";
                Response.Write(strJson);
                Response.End();
            }

        }




         
            
                   






        ///// <summary>
        ///// 检索日期区间内的井数据
        ///// </summary>
        ///// <param name="sender"></param>
        ///// <param name="e"></param>
        //protected void btnSearch_Click(object sender, EventArgs e)
        //{
        //    if (this.txtTs.Text == "" || this.txtTe.Text == "")
        //    {
        //        JScript.Alert(this.Page, "请您选择时间段");
        //    }
        //    else
        //    {
        //        transTime();//转换txt中的日期格式
        //        this.cjrq_s = this.txtTs.Text;
        //        this.cjrq_e = this.txtTe.Text;
        //        this.selectWellid = this.ddllwellid.SelectedValue;//井号列表中当前选中的井号
        //        if (this.drawTb != null)
        //            this.drawTb.Clear();
        //        if (this.checkIsWellid.Checked == true)
        //        {
        //            //通过日期和井号检索
        //            this.drawTb = drawFunc.getWellList_DateAndID(this.cjrq_s, this.cjrq_e, this.selectWellid);
        //        }
        //        else
        //        {
        //            //通过日期检索
        //            this.drawTb = drawFunc.getWellList_Date(this.cjrq_s, this.cjrq_e);
        //        }
        //        this.Session.Add("drawTable", this.drawTb);//将表保存起来
        //        initCheckBoxList();
        //    }
        //}
        ///// <summary>
        ///// 初始化检索出的井号、日期列表
        ///// </summary>
        //protected void initCheckBoxList()
        //{
        //    DataTable dt = (DataTable)Session["drawTable"];//, this.drawTb);//将表保存起来
        //    List<DataViewList> viewList = new List<DataViewList>();

        //    for (int i = 0; i < dt.Rows.Count; i++)
        //    {
        //        DataViewList view = new DataViewList();
        //        view.TxtWellid = this.drawTb.Rows[i][1].ToString();
        //        view.TxtJcrq = this.drawTb.Rows[i][2].ToString();
        //        view.Dvalue = this.drawTb.Rows[i][0].ToString();
        //        viewList.Add(view);
        //    }
        //    this.GridView1.DataSource = viewList;
        //    this.GridView1.DataBind();
        //}

        ///// <summary>
        ///// 转换日期控件中的日期格式，变为与数据库中匹配的
        ///// </summary>
        //protected void transTime()
        //{
        //    string timeS = this.txtTs.Text;
        //    string timeE = this.txtTe.Text;
        //    int i = timeS.IndexOf("/", 3, timeS.Length - 3);
        //    string ts = timeS.Substring(i, 5);
        //    timeS = timeS.Replace(ts, "");
        //    timeS = ts.Substring(1, 4) + "/" + timeS;
        //    this.txtTs.Text = timeS;

        //    int j = timeE.IndexOf("/", 3, timeE.Length - 3);
        //    string te = timeE.Substring(j, 5);
        //    timeE = timeE.Replace(te, "");
        //    timeE = te.Substring(1, 4) + "/" + timeE;
        //    this.txtTe.Text = timeE;
        //}
       
        ///// <summary>
        ///// 初始化时间选择框
        ///// </summary>
        //protected void initTime()
        //{
        //    DataTable dt = new DataTable();
        //    dt = drawFunc.getcurJCRQ();
          
        //}
        ///// <summary>
        ///// 进入页面初始化gridview
        ///// </summary>
        //protected void initGridview()
        //{
        //    this.drawTb = drawFunc.getcurdata();
        //    this.Session.Add("drawTable", this.drawTb);//将表保存起来
        //    initCheckBoxList();
          
        //}

        //protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        //{
        //    //GridViewRow row = GridView1.SelectedRow;
        //    //CheckBox cb = (CheckBox)row.FindControl("check");
        //    //cb.Checked=!cb.Checked;
        //    // row.Cells
        //}

        //protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        //{
        //    if (e.Row.RowType == DataControlRowType.DataRow)
        //    {
        //        e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#C0C0FF';this.style.cursor='hand';");
        //        e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");
        //        e.Row.Attributes["style"] = "cursor:hand";
        //        //#region   //点击行触发SelectedIndexChanged事件
        //        //PostBackOptions myPostBackOptions = new PostBackOptions(this);
        //        //myPostBackOptions.AutoPostBack = false;
        //        //myPostBackOptions.PerformValidation = false;
        //        //myPostBackOptions.RequiresJavaScriptProtocol = true; //加入javascript:头
        //        //String evt = Page.ClientScript.GetPostBackClientHyperlink(sender as GridView, "Select$" + e.Row.RowIndex.ToString());
        //        //e.Row.Attributes.Add("onclick", evt);
        //        //#endregion


        //    }
        //}


    }

   
}
